# 1.1 导入蓝图模块
from flask import Blueprint, session, redirect, request, url_for

# 1.2 创建蓝图对象
admin_blue = Blueprint('admin', __name__)


# 1.3 导入子模块
from . import views


# 对是否是管理员用户的判断，只需要在admin模块实现，所以请求
# 钩子函数只需要在模块内部实现

@admin_blue.before_request
def check_admin():
    is_admin = session.get('is_admin', False)
    if not is_admin and not request.url.endswith(url_for('admin.admin_login')):
        return redirect('/')
